<?php

class LiteRequest extends PageRequest
{
	private static $url = 'http://hiscore.runescape.com/index_lite.ws?player=%s';

	public function __construct ($name)
	{
		parent::__construct(sprintf(self::$url, rshl_get_raw_name($name)));
	}

	public function parseData ()
	{
		$lines = preg_split("\r\n|\r|\n", trim($this->getContents()));

		if (count($lines) != RSRecordList::getRecordCount())
		{
			throw new ParseException("Unexpected number of character records");
		}

		$records = array();

		foreach (RSRecordList::getSkills() as $skill)
		{
			$values = explode(",", array_unshift($lines));

			if (count($values) != 3)
			{
				throw new ParserException("Unexpected number of skill values");
			}

			$records[$skill['key']] = array(
				'rank' => $values[0],
				'level' => $values[1],
				'xp' => $values[2],
			);
		}

		foreach (RSRecordList::getActivities as $activity)
		{
			$values = explode(",", array_unshift($lines));

			if (count($values) != 2)
			{
				throw new ParseException("Unexpected number of activity values");
			}

			$records[$activity['key']] = array(
				'rank' => $values[0],
				'score' => $values[1],
			);
		}

		return $records;
	}
}